package com.iemes.controller.mould;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.PUnloadcheckFromMap;
import com.iemes.entity.PrepareFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.entity.LoadOrderFormMap;
import com.iemes.entity.MouldUnpassHandleFormMap;
import com.iemes.mapper.mould.PUnloadcheckMapper;
import com.iemes.mapper.mould.LoadOrderMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@Controller
@RequestMapping("/loadOrder/")
public class LoadOrderController extends BaseController {

	@Inject
	private LoadOrderMapper loadOrderMapper;
	
	@RequestMapping("loadOrder_list")
	public String examineOrder(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/mould/loadOrder/loadorder_list";
	}
	
	@ResponseBody
	@RequestMapping("loadOrder_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		LoadOrderFormMap loadOrderFormMap = getFormMap(LoadOrderFormMap.class);
		List<Map<String, Object>> loadorder=loadOrderMapper.getAll(loadOrderFormMap);
		LuogicPaging(pageNow, pageSize, loadorder);
		return pageView;
	}
	
	@RequestMapping("loadOrder_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id查询装模指令表
			LoadOrderFormMap load = loadOrderMapper.getById(id);
			model.addAttribute("load",load);
		}
		return Common.BACKGROUND_PATH + "/mould/loadOrder/loadorder_edit";
	}
	
	@ResponseBody
	@RequestMapping(value="loadOrder_editEntity")
	@SystemLog(module="装模指令",methods="装模指令表-修改装模指令表")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		LoadOrderFormMap loadOrderFormMap = getFormMap(LoadOrderFormMap.class);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		loadOrderFormMap.put("date", sdf.format(date));
		// 获取request
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  
		// 通过工具类获取当前登录的bean
		UserFormMap userFormMap = (UserFormMap)Common.findUserSession(request);
		loadOrderFormMap.put("sendPeopleId", userFormMap.getInt("id"));
		baseMapper.editEntity(loadOrderFormMap);
		return "success";
	}
}




